# Maintainer: Ricky Wu <rickleaf.wu@gmail.com>

_realname=luacom
pkgbase=mingw-w64-lua-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-lua51-${_realname}-git"
pkgver=v1.4.1.4.g8f818f5
pkgrel=1
pkgdesc="Microsoft's Component Object Model (COM) Lua interface"
arch=('any')
url="http://luaforge.net/projects/luacom/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-lua51")
options=('staticlibs' 'strip')
source=("${_realname}"::"git+https://github.com/davidm/${_realname}.git"
		"luacom.def"
		"luacom.pc"
		"001-Fix-Lua51-prefix.patch"
		"002-CMake-AR.patch"
		"003-Lua_51_PATH.patch"
		"004-Lua_51_INC.patch")

sha256sums=('SKIP'
		 '59d441b5cd0220d1048ca9e35bde2ba14dae0e5e3b671d53ac6f6d919ca94e60'
         '658379536b0481dba9848f436abc88b7f2beea68259e5ef8184c95aa55411a14'
         '7da5b2ad84bd06777a1d89e2ee4579adac7cfe41dbccc4ae9aeda5a303486a36'
         '70159ab03aa9f52175572339648d31db519beb5f2b89827d668268f7462a732d'
         '1512f081025ee54d5d3144c530de89c1ce90ff6e7d1e5e861833fc044fe605ff'
         'a2944c3cdc37053f7c0d58913a3f7db64387f8f24718b71d3b417a863dfef58e')

pkgver() {
  cd "${srcdir}/${_realname}"
  git describe --tags | sed 's|-|.|g'
}

prepare() {
  cd "${srcdir}"/${_realname}
  patch -p1 -i ${srcdir}/001-Fix-Lua51-prefix.patch
  patch -p1 -i ${srcdir}/002-CMake-AR.patch
  patch -p1 -i ${srcdir}/003-Lua_51_PATH.patch
  patch -p1 -i ${srcdir}/004-Lua_51_INC.patch
}

build() {
  mkdir -p "${srcdir}/${_realname}/build-${MINGW_CHOST}"
  cd "${srcdir}/${_realname}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    ..

  make
  
  dlltool -d ../../luacom.def -l libluacom.dll.a
}

package() {
  cd "${srcdir}/${_realname}/build-${MINGW_CHOST}"
  make destdir=${pkgdir} install
  install -Dm644 libluacom.dll.a "${pkgdir}${MINGW_PREFIX}"/lib/libluacom.dll.a
  install -d "${pkgdir}${MINGW_PREFIX}"/bin
  install -Dm644 luacom.dll "${pkgdir}${MINGW_PREFIX}"/bin/luacom.dll
  install -d "${pkgdir}${MINGW_PREFIX}"/include
  install -Dm644  "${srcdir}/${_realname}"/include/luacom.h "${pkgdir}${MINGW_PREFIX}"/include/lua5.1/luacom.h
  install -d "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig
  install -Dm644  "${srcdir}"/luacom.pc "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/luacom.pc
}
